package com.practice.recursive;

public class Catalan {
	public void print(int l, int r, char[] str, int count) {
		if (l==0 && r==0) print(str);
		if (l>0) {
			str[count] = '(';
			print(l-1, r, str, count+1);
		}
		if (r>l) {
			str[count] = ')';
			print(l, r-1, str, count+1);
		}
	}
	
	private void print(char[] str) {
		System.out.println(new String(str));
	}
	
	public static void main(String[] args) {
		int count = 3;
		new Catalan().print(count, count, new char[2*count], 0);
	}
}
